﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using FantasyBlog.DAL;

namespace FantasyBlog
{
    public class CommentModel:IValidatableObject
    {
        public int ID { get; set; }

        public string author { get; set; }
        public string author_email { get; set; }
        public string comment{ get; set; }
        public int postid { get; set; }
        public int parent { get; set; }
        public CommentModel[] childern; 

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var ErrorList = new List<ValidationResult>();
            var post = Model.PostSet.Find(postid);
            if (post == null)
                ErrorList.Add(new ValidationResult("Can't find " + postid.ToString() + " post"));
            if (parent != 0)
            {
                var pComment = Model.CommentSet.Find(parent);
                if (pComment == null)
                    ErrorList.Add(new ValidationResult("Can't find parent comment"));
            }
            return ErrorList;
        }

        private static BlogModelContainer Model = new BlogModelContainer();
    }
}